<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<table class = "table">
	
	<tr>
		<th>id</th>
		<td>名称</td>
		<td>注册时间</td>
		<td>状态</td>
		<td>角色</td>
		<td>操作</td>
	</tr>
	<c:forEach items="${userPage.list }" var="user">
		<tr>
			<td>${user.id}</td>
			<td>${user.username}</td>
			<td> <fmt:formatDate value="${user.create_time}" pattern="yyyy-MM-dd"/></td>
			<td>${user.locked==0?'正常':'封禁'}</td>
			<td>${user.role==1?'管理员':'注册用户'}</td>
			<td> 
				<c:choose>
				<c:when test="${user.locked==1}">
					<button type="button" class="btn btn-primary" onclick="lockUser(${user.id},0)">解禁</button>
				</c:when>
				<c:when test="${user.locked==0}">
			    	<button type="button" class="btn btn-danger" onclick="lockUser(${user.id},1)" >封禁</button>
			    </c:when>
			    </c:choose>
			 </td>
		</tr>
	</c:forEach>
</table>
<!--分页  -->
					<nav aria-label="Page navigation example">
					  <ul class="pagination">
					    <li class="page-item">
					      <a class="page-link" href="javascript:void(0)"  onclick="gotoPage(1)">
					        <span aria-hidden="true">&laquo;</span>
					      </a>
					    </li>
					    <c:forEach begin="${userPage.pageNum-2>1?userPage.pageNum-2:1 }"
					    	 end="${userPage.pageNum+2<userPage.pages?userPage.pageNum+2:userPage.pages }" step="1" var = "page">
					   	 	<li class="page-item"><a class="page-link" href="javascript:void(0)"    onclick="gotoPage(${page })" >${page }</a></li>
					   </c:forEach>
					    <li class="page-item">
					      <a class="page-link" href="javascript:void(0)" aria-label="Next"  onclick="gotoPage(${userPage.pages})">
					        <span aria-hidden="true">&raquo;</span>
					      </a>
					    </li>
					  </ul>
					</nav>				                                                                                                                  
				<!--分页  -->

<script type="text/javascript">
	function gotoPage(page){
		$("#workContent").load("/admin/showUser?pageNum="+page);
	}
	
	function lockUser(userId,lockedId){
		
		if(confirm("确定限制用户活动吗？")){
			
			$.get("/admin/setUser",{userId:userId,lockedId:lockedId},function(msg){
				
				if(msg.id == 0){
					alert("操作成功！");
					$("#workContent").load("/admin/showUser?page=${userPage.pageNum}");
				}else{
					alert("操作失败！");
				}
				
			},"json");	
		}
		
	}
</script>




